package com.springboot.redis.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @Desc:
 * @Date: 2020-07-12
 * @Version:v1.0
 */
@Service
public class RedisService {

    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * @Desc: redis设置 key-value 值
     * @Param key
     * @Param value
     * @Return void
     * @Date: 2020/7/12
     */
    public void set(String key, String value) {
        ValueOperations<String, String> ops = redisTemplate.opsForValue();
        ops.set(key, value, 1, TimeUnit.MINUTES);
    }

    /**
     * @Desc: 从redis中获取数据
     * @Param key
     * @Return java.lang.String
     * @Date: 2020/7/12
     */
    public String get(String key) {
        ValueOperations<String, String> ops = redisTemplate.opsForValue();
        return ops.get(key);
    }

}
